package com.cd.hospital.www.web;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cd.hospital.modules.entity.NewsEntity;
import com.cd.hospital.modules.service.NewsService;
import com.cd.hospital.common.utils.PageUtils;
import com.cd.hospital.common.utils.Query;
import com.cd.hospital.common.utils.R;

/**
 * 文章
 * 
 * @author weirdor
 * @email 179946422@qq.com
 * @date 2017-09-19 23:26:18
 */
@RestController
@RequestMapping("/modules/news")
public class NewsController {
	@Autowired
	private NewsService newsService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("modules:news:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<NewsEntity> newsList = newsService.queryList(query);
		int total = newsService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(newsList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("modules:news:info")
	public R info(@PathVariable("id") Integer id){
		NewsEntity news = newsService.queryObject(id);
		
		return R.ok().put("news", news);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("modules:news:save")
	public R save(@RequestBody NewsEntity news){
		newsService.save(news);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("modules:news:update")
	public R update(@RequestBody NewsEntity news){
		newsService.update(news);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("modules:news:delete")
	public R delete(@RequestBody Integer[] ids){
		newsService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
